/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fontys.time;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Anh
 */
public class PeriodTest2 {
    
    private IPeriod period;
    IPeriod P = new Period2(new Time(2013, 03, 12, 1, 15), new Time(2013, 03, 12, 1, 30));
    IPeriod A = new Period2(new Time(2013, 03, 12, 1, 0), new Time(2013, 03, 12, 1, 15));
    IPeriod B = new Period2(new Time(2013, 03, 12, 1, 5), new Time(2013, 03, 12, 1, 20));
    IPeriod C = new Period2(new Time(2013, 03, 12, 1, 25), new Time(2013, 03, 12, 1, 28));
    IPeriod D = new Period2(new Time(2013, 03, 12, 1, 12), new Time(2013, 03, 12, 1, 32));
    IPeriod E = new Period2(new Time(2013, 03, 12, 1, 30), new Time(2013, 03, 12, 1, 40));
    IPeriod F = new Period2(new Time(2013, 03, 12, 1, 35), new Time(2013, 03, 12, 1, 55));
    
    public PeriodTest2() {
    }
    
    @BeforeClass
    public static void setUpClass() {
    }
    
    @AfterClass
    public static void tearDownClass() {
    }
    
    @Before
    public void setUp() {
    }
    
    @After
    public void tearDown() {
    }

    @Test
    public void testCreatePeriod(){
        period = new Period(new Time(2000,03,12,1,3), new Time(2001,03,12,1,3)); 
    }
    
    @Test(expected = IllegalArgumentException.class)
    public void testCreateWrongPeriod(){
        period = new Period(new Time(1990,03,12,1,15), new Time(1990,03,12,1,3));   
    }
    
   @Test
    public void testUnionWith(){  
        
        IPeriod x;
        
        x = P.unionWith(A);
       // assertEquals(P.getBeginTime().difference(A.getEndTime()), 0);
        assertEquals(x.length(), 30);
        
        x = P.unionWith(B);
      //  assertEquals(P.getBeginTime().difference(B.getEndTime()), 5);
        assertEquals(x.length(), 25);
        
        x = P.unionWith(C);
        assertEquals(x.getBeginTime().difference(C.getEndTime()), 13);
        assertEquals(x.length(), 15);
        
        x = P.unionWith(D);
       // assertEquals(P.getBeginTime().difference(D.getEndTime()),17);
        assertEquals(x.length(), 20);
        
        x = P.unionWith(E);
       // assertEquals(P.getEndTime().difference(E.getBeginTime()), 0);
        assertEquals(x.length(), 25);
        
        x = P.unionWith(F);
       // assertEquals(P.getEndTime().difference(F.getBeginTime()), 5);
        assertNull(x);
    }
   
   @Test
   public void testIntersectionWith(){
       IPeriod x;
       
       x = P.intersectionWith(A);
       assertEquals(x.getBeginTime().difference(A.getEndTime()), 0);
       assertEquals(x.length(), 0);
       
       x = P.intersectionWith(B);
       assertEquals(x.getBeginTime().difference(B.getEndTime()), 5);
       assertEquals(x.length(), 5);
       
       x = P.intersectionWith(C);
      // assertEquals(P.getBeginTime().difference(C.getEndTime()), 13);
       //assertEquals(P.getEndTime().difference(C.getBeginTime()), 5);
       assertEquals(x.length(), 3);
       
       x = P.intersectionWith(D);
       assertEquals(x.getBeginTime().difference(D.getEndTime()), 17);
       assertEquals(x.getEndTime().difference(D.getBeginTime()), 18);
       assertEquals(x.length(), 15);
       
       x = P.intersectionWith(E);
       assertEquals(x.getEndTime().difference(E.getBeginTime()), 0);
       assertEquals(x.length(), 0);
       
       x = P.intersectionWith(F);
       assertEquals(x, null);
   }
}